package com.inter.law.dao;

import java.util.Date;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.inter.law.entity.IlCase;

/**
 * A data access object (DAO) providing persistence and search support for
 * IlCase entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.inter.law.dao.IlCase
 * @author MyEclipse Persistence Tools
 */

public class IlCaseDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory.getLogger(IlCaseDAO.class);
	// property constants
	public static final String CASE_CHARGE_ID = "caseChargeId";
	public static final String CASE_OFFICE_ID = "caseOfficeId";
	public static final String CASE_NAME = "caseName";
	public static final String CASE_PRE_TYPE = "casePreType";
	public static final String CASE_TYPE = "caseType";
	public static final String CASE_AUXILIARY_TYPE = "caseAuxiliaryType";
	public static final String CASE_SOURCE = "caseSource";
	public static final String CASE_PARTY_TYPE = "casePartyType";
	public static final String CASE_PARTY = "caseParty";
	public static final String CASE_PARTY_COMPANY = "casePartyCompany";
	public static final String CASE_VICTIM = "caseVictim";
	public static final String CASE_TRIAL_GRADE = "caseTrialGrade";
	public static final String CASE_ACQCOST = "caseAcqcost";
	public static final String CASE_CLIENT = "caseClient";
	public static final String CASE_IS_NONAGE = "caseIsNonage";
	public static final String CASE_IS_TPSD = "caseIsTpsd";
	public static final String CASE_REASON = "caseReason";
	public static final String CASE_CLIENT_TYPE = "caseClientType";
	public static final String CASE_CONTRAY_CLIENT = "caseContrayClient";
	public static final String CASE_CONTRAY_CLIENT_TYPE = "caseContrayClientType";
	public static final String CASE_PROFILE = "caseProfile";
	public static final String CASE_IS_SPECIAL = "caseIsSpecial";
	public static final String CASE_BILING_METHOD = "caseBilingMethod";
	public static final String CASE_BILING_NOTES = "caseBilingNotes";
	public static final String CASE_CHARGE_REDUCTION = "caseChargeReduction";
	public static final String CASE_BENEFIT_TYPE = "caseBenefitType";
	public static final String CASE_NOTES = "caseNotes";
	public static final String CASE_PROTOCOL = "caseProtocol";
	public static final String CASE_LAWER_ID = "caseLawerId";
	public static final String CASE_STATUS = "caseStatus";
	public static final String CASE_NUMBER = "caseNumber";

	protected void initDao() {
		// do nothing
	}

	public void save(IlCase transientInstance) {
		log.debug("saving IlCase instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(IlCase persistentInstance) {
		log.debug("deleting IlCase instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public IlCase findById(java.lang.Integer id) {
		log.debug("getting IlCase instance with id: " + id);
		try {
			IlCase instance = (IlCase) getHibernateTemplate().get(
					"com.inter.law.entity.IlCase", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(IlCase instance) {
		log.debug("finding IlCase instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding IlCase instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from IlCase as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCaseChargeId(Object caseChargeId) {
		return findByProperty(CASE_CHARGE_ID, caseChargeId);
	}

	public List findByCaseOfficeId(Object caseOfficeId) {
		return findByProperty(CASE_OFFICE_ID, caseOfficeId);
	}

	public List findByCaseName(Object caseName) {
		return findByProperty(CASE_NAME, caseName);
	}

	public List findByCasePreType(Object casePreType) {
		return findByProperty(CASE_PRE_TYPE, casePreType);
	}

	public List findByCaseType(Object caseType) {
		return findByProperty(CASE_TYPE, caseType);
	}

	public List findByCaseAuxiliaryType(Object caseAuxiliaryType) {
		return findByProperty(CASE_AUXILIARY_TYPE, caseAuxiliaryType);
	}

	public List findByCaseSource(Object caseSource) {
		return findByProperty(CASE_SOURCE, caseSource);
	}

	public List findByCasePartyType(Object casePartyType) {
		return findByProperty(CASE_PARTY_TYPE, casePartyType);
	}

	public List findByCaseParty(Object caseParty) {
		return findByProperty(CASE_PARTY, caseParty);
	}

	public List findByCasePartyCompany(Object casePartyCompany) {
		return findByProperty(CASE_PARTY_COMPANY, casePartyCompany);
	}

	public List findByCaseVictim(Object caseVictim) {
		return findByProperty(CASE_VICTIM, caseVictim);
	}

	public List findByCaseTrialGrade(Object caseTrialGrade) {
		return findByProperty(CASE_TRIAL_GRADE, caseTrialGrade);
	}

	public List findByCaseAcqcost(Object caseAcqcost) {
		return findByProperty(CASE_ACQCOST, caseAcqcost);
	}

	public List findByCaseClient(Object caseClient) {
		return findByProperty(CASE_CLIENT, caseClient);
	}

	public List findByCaseIsNonage(Object caseIsNonage) {
		return findByProperty(CASE_IS_NONAGE, caseIsNonage);
	}

	public List findByCaseIsTpsd(Object caseIsTpsd) {
		return findByProperty(CASE_IS_TPSD, caseIsTpsd);
	}

	public List findByCaseReason(Object caseReason) {
		return findByProperty(CASE_REASON, caseReason);
	}

	public List findByCaseClientType(Object caseClientType) {
		return findByProperty(CASE_CLIENT_TYPE, caseClientType);
	}

	public List findByCaseContrayClient(Object caseContrayClient) {
		return findByProperty(CASE_CONTRAY_CLIENT, caseContrayClient);
	}

	public List findByCaseContrayClientType(Object caseContrayClientType) {
		return findByProperty(CASE_CONTRAY_CLIENT_TYPE, caseContrayClientType);
	}

	public List findByCaseProfile(Object caseProfile) {
		return findByProperty(CASE_PROFILE, caseProfile);
	}

	public List findByCaseIsSpecial(Object caseIsSpecial) {
		return findByProperty(CASE_IS_SPECIAL, caseIsSpecial);
	}

	public List findByCaseBilingMethod(Object caseBilingMethod) {
		return findByProperty(CASE_BILING_METHOD, caseBilingMethod);
	}

	public List findByCaseBilingNotes(Object caseBilingNotes) {
		return findByProperty(CASE_BILING_NOTES, caseBilingNotes);
	}

	public List findByCaseChargeReduction(Object caseChargeReduction) {
		return findByProperty(CASE_CHARGE_REDUCTION, caseChargeReduction);
	}

	public List findByCaseBenefitType(Object caseBenefitType) {
		return findByProperty(CASE_BENEFIT_TYPE, caseBenefitType);
	}

	public List findByCaseNotes(Object caseNotes) {
		return findByProperty(CASE_NOTES, caseNotes);
	}

	public List findByCaseProtocol(Object caseProtocol) {
		return findByProperty(CASE_PROTOCOL, caseProtocol);
	}

	public List findByCaseLawerId(Object caseLawerId) {
		return findByProperty(CASE_LAWER_ID, caseLawerId);
	}

	public List findByCaseStatus(Object caseStatus) {
		return findByProperty(CASE_STATUS, caseStatus);
	}

	public List findByCaseNumber(Object caseNumber) {
		return findByProperty(CASE_NUMBER, caseNumber);
	}

	public List findAll() {
		log.debug("finding all IlCase instances");
		try {
			String queryString = "from IlCase";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public IlCase merge(IlCase detachedInstance) {
		log.debug("merging IlCase instance");
		try {
			IlCase result = (IlCase) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(IlCase instance) {
		log.debug("attaching dirty IlCase instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(IlCase instance) {
		log.debug("attaching clean IlCase instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IlCaseDAO getFromApplicationContext(ApplicationContext ctx) {
		return (IlCaseDAO) ctx.getBean("IlCaseDAO");
	}
}